<?php

namespace common\models;

use Yii;

/**
 * This is the model class for table "favorite_member".
 *
 * @property integer $favorite_member_id
 * @property integer $member_id
 * @property integer $be_favorite_member_id
 * @property integer $create_time
 */
class FavoriteMember extends \yii\db\ActiveRecord
{
    /**
     * @inheritdoc
     */
    public static function tableName()
    {
        return 'favorite_member';
    }

    /**
     * @inheritdoc
     */
    public function rules()
    {
        return [
            [['member_id', 'be_favorite_member_id', 'create_time'], 'required'],
            [['member_id', 'be_favorite_member_id', 'create_time'], 'integer'],
        ];
    }

    /**
     * @inheritdoc
     */
    public function attributeLabels()
    {
        return [
            'favorite_member_id' => 'ID',
            'member_id' => '会员id',
            'be_favorite_member_id' => '被收藏会员ID',
            'create_time' => '创建时间',
        ];
    }

    /**
     *  关联Member表
     */
    public function getMember()
    {
        // hasOne要求返回两个参数 第一个参数是关联表的类名 第二个参数是两张表的关联关系
        // 这里member_id是member表关联id, 关联favorite表的member_id member是当前模型的主键member
        return $this->hasOne(Member::className(), ['member_id' => 'be_favorite_member_id']);
    }

}
